package org.jiuling.sms.aliyun.config;

import org.jiuling.aliyun.config.AliYunConfig;
import org.jiuling.aliyun.sms.AliYunSms;
import org.jiuling.aliyun.sms.config.AliYunSmsConfig;
import org.jiuling.aliyun.sms.factory.AliYunSmsFactory;
import org.jiuling.aliyun.sms.factory.impl.AliYunSmsFactoryImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 阿里云短信Bean配置
 * @author 紫灵
 * @date 2023年01月04日 10时04分29秒
 */
@Component
@Configuration
public class AliYunSmsBeanConfig {

    private final AliYunConfig aliYunConfig;

    public AliYunSmsBeanConfig(AliYunConfig aliYunConfig) {
        this.aliYunConfig = aliYunConfig;
    }

    @Bean
    @ConfigurationProperties(prefix = "jiu-ling.aliyun.sms")
    public AliYunSmsConfig aliYunSmsConfig(){
        return new AliYunSmsConfig(aliYunConfig);
    }

    @Bean
    public AliYunSms aliYunSms(){
        return new AliYunSms(aliYunSmsConfig());
    }

    @Bean
    public AliYunSmsFactory aliYunSmsFactory(){
        return new AliYunSmsFactoryImpl(aliYunSmsConfig().getPattern(),aliYunSmsConfig());
    }
}
